﻿<UserControl 
    xmlns:am="http://schemas.amcharts.com/charts/wpf/2009/xaml"  
    x:Class="NMortgage.UI.Views.SimulationView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:wpf="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
        xmlns:Properties="clr-namespace:NMortgage.UI.Properties" mc:Ignorable="d" d:DesignHeight="600"
        d:DesignWidth="600">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Themes/CommonStyles.xaml" />
                <ResourceDictionary Source="../Themes/LoanProfileStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*" MinWidth="150" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="7*" MinWidth="150" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="5*" MinHeight="150" />
            <RowDefinition Height="5" />
            <RowDefinition Height="5*" />
        </Grid.RowDefinitions>

        <GridSplitter Style="{StaticResource VGridSplit}" 
                  Grid.Column="1" />
        <GridSplitter Style="{StaticResource HGridSplit}" 
                  Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" />

        <Button x:Name="ShowAmortization" Content="Show Amortization" Width="150" Height="35" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10" />

        <am:LineChart Grid.Column="2"
              HideBulletsCount="18" PlotAreaMargin="50,40,40,40" 
              BorderBrush="#0F000000" BorderThickness="1" 
              IndicatorStroke="#880D8ECF" IndicatorBalloonForeground="White" 
              SelectionBrush="#200D8ECF" ZoomOutButtonHoverForeground="#FFFF0F00" 
              ZoomOutButtonMargin="0,60,50,0" Name="AmortizationChart"
                      SeriesSource="{Binding Path=Payments}"
                      IDMemberPath="PaymentDate">
            <am:LineChart.Resources>
                <am:DoubleToStringValueConverter x:Key="doubleToStringConverter" />
            </am:LineChart.Resources>
           
            <am:LineChartGraph Title="Mortgage Balance" IsSelected="True" Name="Balance"
                             DataItemsSource="{Binding Path=Payments}" 
                             SeriesIDMemberPath="PaymentDate"
                             ValueMemberPath="EndingBalance">
                <am:LineChartGraph.BalloonTemplate>
                    <ControlTemplate>
                        <am:BalloonFrame>
                            <TextBlock Padding="4" TextWrapping="Wrap" >
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0:d}: {1:C}">
                                    <Binding Path="DataContext.PaymentDate" />
                                    <Binding Path="DataContext.EndingBalance" />
                                </MultiBinding>
                            </TextBlock.Text>
                            </TextBlock>
                        </am:BalloonFrame>
                    </ControlTemplate>
                </am:LineChartGraph.BalloonTemplate>
            </am:LineChartGraph>

            <am:LineChartGraph Title="Cumulative Interest" IsSelected="True" Name="Interest"
                               DataItemsSource="{Binding Path=Payments}"
                             SeriesIDMemberPath="PaymentDate"
                             ValueMemberPath="CumulativeInterest">
                <am:LineChartGraph.BalloonTemplate>
                    <ControlTemplate>
                        <am:BalloonFrame>
                            <TextBlock Padding="4" TextWrapping="Wrap" >
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0:d}: {1:C}">
                                    <Binding Path="DataContext.PaymentDate" />
                                    <Binding Path="DataContext.CumulativeInterest" />
                                </MultiBinding>
                            </TextBlock.Text>
                            </TextBlock>
                        </am:BalloonFrame>
                    </ControlTemplate>
                </am:LineChartGraph.BalloonTemplate>                                
            </am:LineChartGraph>

            <am:LineChartGraph Title="Principal Paid" IsSelected="True" Name="Principal"
                               DataItemsSource="{Binding Path=Payments}"
                             SeriesIDMemberPath="PaymentDate"
                             ValueMemberPath="CumulativePrincipal">
                <am:LineChartGraph.BalloonTemplate>
                    <ControlTemplate>
                        <am:BalloonFrame>
                            <TextBlock Padding="4" TextWrapping="Wrap" >
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0:d}: {1:C}">
                                    <Binding Path="DataContext.PaymentDate" />
                                    <Binding Path="DataContext.CumulativePrincipal" />
                                </MultiBinding>
                            </TextBlock.Text>
                            </TextBlock>
                        </am:BalloonFrame>
                    </ControlTemplate>
                </am:LineChartGraph.BalloonTemplate>
            </am:LineChartGraph>

            
            <am:LineChart.CategoryAxis>
                <am:CategoryAxis TickLength="12" ValuesRotationAngle="-12" >
                </am:CategoryAxis>
            </am:LineChart.CategoryAxis>

            <am:LineChart.Legend>
                <am:Legend ReverseOrder="false" Position="Top" 
                                                IsGraphTogglingEnabled="True" 
                                                Margin="0,0,0,0"
                                                VerticalAlignment="Center" Visibility="Visible"  />
            </am:LineChart.Legend>
        </am:LineChart>


        <wpf:DataGrid x:Name="Payments" AutoGenerateColumns="False" IsReadOnly="True" Grid.Row="2" Grid.ColumnSpan="3">
            <wpf:DataGrid.Columns>
                <wpf:DataGridTextColumn Binding="{Binding Path=Period}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderPaymentNumber}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=PaymentDate, StringFormat={}{0:d}}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderPaymentDate}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=StandardPayment, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="Stanard Payment" />
                <wpf:DataGridTextColumn Binding="{Binding Path=ExtraPayment, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="Extra Payment" />
                <wpf:DataGridTextColumn Binding="{Binding Path=PaymentMade, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderPaymentAmount}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=InterestDescription}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderInterestRate}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=InterestDue, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderInterestDue}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=PrincipleDue, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderPrincipalDue}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=BeginingBalance, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderBeginningBalance}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=EndingBalance, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderEndingBalance}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=CumulativePrincipal, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderCumulativePrincipal}" />
                <wpf:DataGridTextColumn Binding="{Binding Path=CumulativeInterest, StringFormat={}{0:C}}"
                        ElementStyle="{StaticResource Numeric}"
                        Header="{x:Static Properties:Resources.SimulationColumnHeaderCumulativeInterest}" />
            </wpf:DataGrid.Columns>
        </wpf:DataGrid>
    </Grid>
</UserControl>
